/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package estg.dae.projecto.bank.model;

import estg.dae.projecto.bank.IBank;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Date;
import java.util.Properties;

/**
 *
 * @author Marco
 */
public class BankSettings implements IBank, Serializable {
    private static String BANK_CONF_FILE_URL = "estg/dae/projecto/bank/utils/bank.properties";
    private static BankSettings bankSettings;
    private String name;
    private String code;
    private String address;
    private String phone;
    private String responsibleName;
    private String responsibleEmail;
    private String shortName;
    private String hostName;
    private int hostPort;
    private Date offlineTransfersTime;

    protected BankSettings() {
        try {
            InputStream is = this.getClass().getClassLoader().
                    getResourceAsStream(BANK_CONF_FILE_URL);
            Properties conf = new Properties();
            conf.load(is);

            name = conf.getProperty("bank.name");
            code = conf.getProperty("bank.code");
            address = conf.getProperty("bank.address");
            phone = conf.getProperty("bank.phone");
            responsibleName = conf.getProperty("bank.responsibleName");
            responsibleEmail = conf.getProperty("bank.responsibleEmail");
            shortName = conf.getProperty("bank.shortName");
            hostName = conf.getProperty("bank.hostname");
            hostPort = Integer.parseInt(conf.getProperty("bank.hostport"));
            is.close();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static BankSettings getInstance() {
        if (bankSettings == null)
            bankSettings = new BankSettings();

        return bankSettings;
    }

    public Date getOfflineTransfersTime() {
        return offlineTransfersTime;
    }

    public void setOfflineTransfersTime(Date offlineTransfersTime) {
        this.offlineTransfersTime = offlineTransfersTime;
    }

    public String getName() {
        return name;
    }

    public String getCode() {
        return code;
    }

    public String getAddress() {
        return address;
    }

    public String getPhone() {
        return phone;
    }

    public String getResponsibleName() {
        return responsibleName;
    }

    public String getResponsibleEmail() {
        return responsibleEmail;
    }

    public String getShortName() {
        return shortName;
    }

    public String getHostName() {
        return hostName;
    }

    public int getHostPort() {
        return hostPort;
    }

}
